package com.databasedesign.controller;

import com.databasedesign.pojo.dto.Result;
import com.databasedesign.pojo.dto.StudentDTO;
import com.databasedesign.pojo.po.Student;
import com.databasedesign.service.DormitoryService;
import com.databasedesign.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
@CrossOrigin
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private DormitoryService dormitoryService;

    /**
     * 查询全部新生信息(不包括宿舍信息)
     * @return
     */
    @GetMapping("student/all")
    public Result GetAllStuddent(){
        List list = new ArrayList();
        list = studentService.GetAll();
        return new Result(200,"查询全部新生",list);
    }

    /**
     * 查询单个新生信息(不包括宿舍信息)
     * @param StudentId 学生ID
     * @return
     */
    @GetMapping("student/{StudentId}")
    public Result GetStudentById(@PathVariable String StudentId){
        Student student = new Student();
        student = studentService.GetByStudentId(StudentId);
        return new Result(200,"根据学号查询新生",student);
    }


    /**
     * 根据宿舍号查询新生
     * @param RoomNumber 宿舍号，如 1-201
     * @return
     */
    @GetMapping("student/RoomNumber/{RoomNumber}")
    public Result GetStudentByRoomNumber(@PathVariable String RoomNumber){
        List<Student> studentList = new ArrayList<Student>();
        studentList = studentService.GetByRoomNumber(RoomNumber);
        return new  Result(200,"根据宿舍号查新生",studentList);
    }

    /**
     * 根据学号查询宿舍号
     * @param StudentNumber 学号，如20150810008
     * @return
     */
    @GetMapping("dormitory/StudentNumber/{StudentNumber}")
    public Result GetStudentByStudentNumber(@PathVariable String StudentNumber){
        String DormitoryNumber = studentService.GetByStudentNumber(StudentNumber);
        Map<String, String> DormitoryNumberMap = new HashMap<>();
        DormitoryNumberMap.put("roomNumber",DormitoryNumber);
        return new  Result(200,"根据学号查宿舍号",DormitoryNumberMap);
    }

    /**
     * 根据学院或者专业名查询学生及宿舍号
     * @param CollegeOrSubject 学院或者专业名，如会计学
     * @return
     */
    @GetMapping("student/CollegeOrSubject/{CollegeOrSubject}")
    public Result GetDormitoryByCollegeOrSubject(@PathVariable String CollegeOrSubject){
        List<StudentDTO> studentList = studentService.GetDormitoryByCollegeOrSubject(CollegeOrSubject);
        return new Result(200,"根据学院或者专业名查询学生及宿舍号",studentList);
    }


}
